﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using Entities;
using Business;
using System.IO;
namespace Presentation
{
    public partial class frmMain :DevComponents.DotNetBar.Office2007RibbonForm
    {
        public NguoiDungDTO nguoiDung;
        public frmMain()
        {
            InitializeComponent();
            //styleManager1.ManagerStyle = eStyle.Office2007Black;           
            
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            lbNguoiDung.Text += nguoiDung.HoTen;
            lbChucVu.Text +=ChucVuService.GetChucVu(nguoiDung.MaChucVu).TenChucVu;
            if (nguoiDung.MaChucVu == 2)
            {
                ribbonTabItem1.Enabled = false;
            }
            else if (nguoiDung.MaChucVu == 3)
            {
                mnuDauSach.Enabled = false;
                mnuTheLoai.Enabled = false;
                mnuTacGia.Enabled = false;
                mnuLapPhieuNhapSach.Enabled = false;
            }
        }
        private void mnuTheLoai_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name=="TheLoai")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmQuanLyTheLoai f = new frmQuanLyTheLoai();
            f.Name = "TheLoai";
            f.MdiParent = this;            
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }
        private void cbxStyle_Click(object sender, EventArgs e)
        {
            //asdasdasd
        }

        private void cbxStyle_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void mnuLapPhieuNhapSach_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "LapPhieuNhapSach")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmLapPhieuNhapSach f = new frmLapPhieuNhapSach();
            f.nguoiDung = this.nguoiDung;
            f.Name = "LapPhieuNhapSach";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void buttonItem7_Click(object sender, EventArgs e)
        {

        }

        private void mnuDauSach_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "DauSach")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmQuanLySach f = new frmQuanLySach();
            f.Name = "DauSach";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuTacGia_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "TacGia")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmQuanLyTacGia f = new frmQuanLyTacGia();
            f.Name = "TacGia";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuLapHoaDonBanSach_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "LapHoaDonBanSach")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmLapHoaDon f = new frmLapHoaDon();
            f.Name = "LapHoaDonBanSach";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuTraCuuSach_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "TraCuuSach")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmTraCuuSach f = new frmTraCuuSach();
            f.Name = "TraCuuSach";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuLapPhieuThuTien_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "LapPhieuThuTien")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmLapPhieuThuTien f = new frmLapPhieuThuTien();
            f.Name = "LapPhieuThuTien";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuQuanLyKhachHang_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "QuanLyKhachHang")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
             frmQuanLyKhachHang f= new frmQuanLyKhachHang();
            f.Name = "QuanLyKhachHang";
            f.MdiParent = this;
            //f.WindowState = FormWindowState.Maximized;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void mnuThayDoiQuiDinh_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "ThayDoiQuyDinh")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmThayDoiQuyDinh f = new frmThayDoiQuyDinh();
            f.Name = "ThayDoiQuyDinh";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuBaoCaoCongNo_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "BaoCaoCongNo")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmLapBaoCaoCongNo f = new frmLapBaoCaoCongNo();
            f.nguoiDung = this.nguoiDung;
            f.Name = "BaoCaoCongNo";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void btnLapBaoCaoTon_Click(object sender, EventArgs e)
        {
             foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "BaoCaoTon")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmLapBaoCaoTon f = new frmLapBaoCaoTon();
            f.Name = "BaoCaoTon";
            f.nguoiDung = this.nguoiDung;
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        
        }

        private void btnDoiMatKhau_Click(object sender, EventArgs e)
        {
            frmDoiMatKhau f = new frmDoiMatKhau();
            f.StartPosition = FormStartPosition.CenterParent;
            f.nguoiDung = this.nguoiDung;
            f.ShowDialog();
        }

        private void mnuThongTinPhanMem_Click(object sender, EventArgs e)
        {
            frmAbout f = new frmAbout();
            f.StartPosition = FormStartPosition.CenterParent;
            f.ShowDialog();
        }

        private void mnuTraCuuKhachHang_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "TraCuuKhachHang")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmTraCuuKhachHang f = new frmTraCuuKhachHang();
            f.Name = "TraCuuKhachHang";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuQuanLyNguoiDung_Click(object sender, EventArgs e)
        {
            foreach (Form i in this.MdiChildren)
            {
                if (i.Name == "QuanLyNguoiDung")
                {
                    this.ActivateMdiChild(i);
                    return;
                }
            }
            frmQuanLyNguoiDung f = new frmQuanLyNguoiDung();
            f.Name = "QuanLyNguoiDung";
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.Show();
        }

        private void mnuHuongDan_Click(object sender, EventArgs e)
        {
            string path = Application.StartupPath + @"\Help.chm";
            if (File.Exists(path))
            {
                System.Diagnostics.Process.Start(path);
            }
            else
            {
                MessageBoxEx.Show("Không tìm thấy " + path, "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void buttonItem6_Click(object sender, EventArgs e)
        {

        }
    }
}
